Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gogrep: use slices instead of maps for capture data #209

Merged
merged 1 commit into from
Feb 4, 2021

Conversation

quasilyte
Copy link
Owner

Since most patterns have less than 8 variables (usually, 1-4),
it's more efficient to use key-value slices instead of maps.
They also make memory reusing easier.

Even for 8 vars, slices are more efficient here.

name                           old time/op    new time/op    delta
Match/simpleLit-8                 217ns ± 3%     123ns ± 4%  -43.33%  (p=0.008 n=5+5)
Match/capture1-8                  652ns ± 7%     275ns ± 2%  -57.79%  (p=0.008 n=5+5)
Match/capture2-8                  950ns ± 0%     438ns ± 1%  -53.84%  (p=0.008 n=5+5)
Match/capture8-8                 3.89µs ± 5%    2.51µs ± 0%  -35.57%  (p=0.008 n=5+5)
Match/capture2same-8              947ns ± 2%     458ns ± 6%  -51.68%  (p=0.008 n=5+5)
Match/capture8same-8             3.42µs ± 2%    2.31µs ± 2%  -32.36%  (p=0.008 n=5+5)
Match/captureBacktrackLeft-8     5.87µs ± 1%    4.43µs ± 1%  -24.60%  (p=0.008 n=5+5)
Match/captureBacktrackRight-8    4.80µs ± 0%    2.43µs ± 3%  -49.42%  (p=0.008 n=5+5)

name                           old alloc/op   new alloc/op   delta
Match/simpleLit-8                 80.0B ± 0%     32.0B ± 0%  -60.00%  (p=0.008 n=5+5)
Match/capture1-8                   416B ± 0%       32B ± 0%  -92.31%  (p=0.008 n=5+5)
Match/capture2-8                   464B ± 0%       32B ± 0%  -93.10%  (p=0.008 n=5+5)
Match/capture8-8                   896B ± 0%      128B ± 0%  -85.71%  (p=0.008 n=5+5)
Match/capture2same-8               464B ± 0%       32B ± 0%  -93.10%  (p=0.008 n=5+5)
Match/capture8same-8               896B ± 0%      128B ± 0%  -85.71%  (p=0.008 n=5+5)
Match/captureBacktrackLeft-8     2.75kB ± 0%    0.85kB ± 0%  -69.19%  (p=0.008 n=5+5)
Match/captureBacktrackRight-8    2.54kB ± 0%    0.43kB ± 0%  -83.02%  (p=0.008 n=5+5)

name                           old allocs/op  new allocs/op  delta
Match/simpleLit-8                  2.00 ± 0%      1.00 ± 0%  -50.00%  (p=0.008 n=5+5)
Match/capture1-8                   4.00 ± 0%      1.00 ± 0%  -75.00%  (p=0.008 n=5+5)
Match/capture2-8                   5.00 ± 0%      1.00 ± 0%  -80.00%  (p=0.008 n=5+5)
Match/capture8-8                   15.0 ± 0%       4.0 ± 0%  -73.33%  (p=0.008 n=5+5)
Match/capture2same-8               5.00 ± 0%      1.00 ± 0%  -80.00%  (p=0.008 n=5+5)
Match/capture8same-8               15.0 ± 0%       4.0 ± 0%  -73.33%  (p=0.008 n=5+5)
Match/captureBacktrackLeft-8       31.0 ± 0%      21.0 ± 0%  -32.26%  (p=0.008 n=5+5)
Match/captureBacktrackRight-8      25.0 ± 0%      12.0 ± 0%  -52.00%  (p=0.008 n=5+5)

Since most patterns have less than 8 variables (usually, 1-4),
it's more efficient to use key-value slices instead of maps.
They also make memory reusing easier.

Even for 8 vars, slices are more efficient here.

```
name                           old time/op    new time/op    delta
Match/simpleLit-8                 217ns ± 3%     123ns ± 4%  -43.33%  (p=0.008 n=5+5)
Match/capture1-8                  652ns ± 7%     275ns ± 2%  -57.79%  (p=0.008 n=5+5)
Match/capture2-8                  950ns ± 0%     438ns ± 1%  -53.84%  (p=0.008 n=5+5)
Match/capture8-8                 3.89µs ± 5%    2.51µs ± 0%  -35.57%  (p=0.008 n=5+5)
Match/capture2same-8              947ns ± 2%     458ns ± 6%  -51.68%  (p=0.008 n=5+5)
Match/capture8same-8             3.42µs ± 2%    2.31µs ± 2%  -32.36%  (p=0.008 n=5+5)
Match/captureBacktrackLeft-8     5.87µs ± 1%    4.43µs ± 1%  -24.60%  (p=0.008 n=5+5)
Match/captureBacktrackRight-8    4.80µs ± 0%    2.43µs ± 3%  -49.42%  (p=0.008 n=5+5)

name                           old alloc/op   new alloc/op   delta
Match/simpleLit-8                 80.0B ± 0%     32.0B ± 0%  -60.00%  (p=0.008 n=5+5)
Match/capture1-8                   416B ± 0%       32B ± 0%  -92.31%  (p=0.008 n=5+5)
Match/capture2-8                   464B ± 0%       32B ± 0%  -93.10%  (p=0.008 n=5+5)
Match/capture8-8                   896B ± 0%      128B ± 0%  -85.71%  (p=0.008 n=5+5)
Match/capture2same-8               464B ± 0%       32B ± 0%  -93.10%  (p=0.008 n=5+5)
Match/capture8same-8               896B ± 0%      128B ± 0%  -85.71%  (p=0.008 n=5+5)
Match/captureBacktrackLeft-8     2.75kB ± 0%    0.85kB ± 0%  -69.19%  (p=0.008 n=5+5)
Match/captureBacktrackRight-8    2.54kB ± 0%    0.43kB ± 0%  -83.02%  (p=0.008 n=5+5)

name                           old allocs/op  new allocs/op  delta
Match/simpleLit-8                  2.00 ± 0%      1.00 ± 0%  -50.00%  (p=0.008 n=5+5)
Match/capture1-8                   4.00 ± 0%      1.00 ± 0%  -75.00%  (p=0.008 n=5+5)
Match/capture2-8                   5.00 ± 0%      1.00 ± 0%  -80.00%  (p=0.008 n=5+5)
Match/capture8-8                   15.0 ± 0%       4.0 ± 0%  -73.33%  (p=0.008 n=5+5)
Match/capture2same-8               5.00 ± 0%      1.00 ± 0%  -80.00%  (p=0.008 n=5+5)
Match/capture8same-8               15.0 ± 0%       4.0 ± 0%  -73.33%  (p=0.008 n=5+5)
Match/captureBacktrackLeft-8       31.0 ± 0%      21.0 ± 0%  -32.26%  (p=0.008 n=5+5)
Match/captureBacktrackRight-8      25.0 ± 0%      12.0 ± 0%  -52.00%  (p=0.008 n=5+5)
```
@quasilyte quasilyte merged commit cc68f68 into master Feb 4, 2021
@quasilyte quasilyte deleted the quasilyte/gogrep/captured_slice branch February 4, 2021 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant